package com.tanguy.user.ui.me.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tanguy.user.R;
import com.tanguy.user.bean.station.CityBean;
import com.tanguy.user.interfaces.OnDataCallBack;

import java.util.List;


/**
 * Created by dab on 2017/8/14 0014 18:06
 * 城市
 */

public class CityAdapter extends RecyclerView.Adapter<CityAdapter.ViewHolder> {
    private List<CityBean> mCityBeans;
    private OnDataCallBack<CityBean> mDataCallBack;

    public void setDataCallBack(OnDataCallBack<CityBean> dataCallBack) {
        mDataCallBack = dataCallBack;
    }

    public void setCityBeans(List<CityBean> cityBeans) {
        mCityBeans = cityBeans;
        notifyDataSetChanged();
    }



    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_car_brand_type, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CityBean cityBean = mCityBeans.get(position);
        holder.mTvType.setText(cityBean.getName());
        if (mDataCallBack != null) {
            holder.itemView.setOnClickListener(view -> mDataCallBack.onCallBack(cityBean));
        }


    }

    @Override
    public int getItemCount() {
        return mCityBeans == null ? 0 : mCityBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTvType;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvType = itemView.findViewById(R.id.tv_type);

        }
    }
}
